<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>新增饮品</title>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/reset.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/common.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome.min.css">
<!--公共样式结束-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/module_form.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/page_memberAdd.css">
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.min.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.timer.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/common.js"></script>
<script src="__PUBLIC__/Plugins/Datepicker/WdatePicker.js"></script>
</head>

<body>
	<div class="page_header">
		<div class="tabbar">
			<ul class="tab clearfix" tabname="tab1">
				<li class="tabhover" show="tab1_0">基本信息</li>
				<li class="" show="tab1_1">缩略图</li>
			</ul>
		</div>
	</div>
	<div class="page_wraper">
		<form method="post" id="restaurantAdd_form">
			<div id="tab1_0" fortab="tab1">
				<input type="hidden" id="solevar" name="solevar" value="{:create_id()}">
			<table cellpadding="0" cellspacing="0" class="module_form" width="600">
			<fieldset>
				<tr>
					<td class="ele_title"><label for="cardnum">中文名称：<em>*</em></label></td>
					<td class="ele_content">
						<input name="title" type="text" id="title" class="form_ele_text width_200">
					</td>
					<td class="ele_title"><label for="cardnum">英文名称：<em>*</em></label></td>
					<td class="ele_content">
						<input name="entitle" type="text" id="entitle" class="form_ele_text width_200">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">成本价格：<em>*</em></label></td>
					<td class="ele_content">
						<input name="mprice" type="text" id="mprice" class="form_ele_text width_200">
					</td>
					<td class="ele_title"><label for="realname">销售价格：<em>*</em></label></td>
					<td class="ele_content">
						<input name="sprice" type="text" id="sprice" class="form_ele_text">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="sex">类型：</label></td>
					<td class="ele_content">
						<select class="width_200" name="type" id="type">
							<option value="">请选择</option>
							<volist name="drinkArr" id="v">
								<option value="{$key}">{$v[0]}</option>
							</volist>
						</select>
					</td>
					<td class="ele_title"><label for="realname">库存：<em>*</em></label></td>
					<td class="ele_content">
						<input name="num" type="text" id="num" class="form_ele_text">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">商品编号：<em>*</em></label></td>
					<td class="ele_content">
						<input name="drink_num" type="text" id="drink_num" class="form_ele_text width_200">
					</td>
					<td class="ele_title"><label for="entitle">排序号：<em>*</em></label></td>
					<td class="ele_content">
						<input name="sort" type="text" value="0" class="form_ele_text width_200">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">是否显示：<em>*</em></label></td>
					<td class="ele_content" colspan="3">
						<input name="isshow" type="radio" id="isshow" value="1" checked>是&nbsp;&nbsp;&nbsp;
						<input name="isshow" type="radio" id="isshow" value="2">否
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="address1">所属地区：</label></td>
					<td class="ele_content" colspan="3">
						<div id="areaBox"></div>
					</td>
				</tr>
				<tr>
					<td class="ele_title width_150"><label for="remark">简介（中文）：</label></td>
					<td class="ele_content" colspan="3">
						<textarea name="content" cols="" rows="" id="content"></textarea></td>
				</tr>
				<tr>
					<td class="ele_title width_150"><label for="remark">简介（英文）：</label></td>
					<td class="ele_content" colspan="3">
						<textarea name="encontent" cols="" rows="" id="encontent"></textarea></td>
				</tr>
				</fieldset>
				<tr>
					<td colspan="4" style="height:30px;"></td>
				</tr>
			</table>
		</div>
		<div id="tab1_1" fortab="tab1">
				<table cellpadding="0" cellspacing="0" class="module_form" width="600">
					<tr>
						<td class="ele_title"><label for="title">缩略图（4:3）：</label></td>
						<td class="ele_content" colspan="3">
							<div class="thumb">
								<img src="__PUBLIC__/Images/nothumb.jpg"/>
								<input type="hidden" value="" name="thumb_url[]" id="thumb_url">
								<input type="hidden" name="thumb_title[]" value="">
								<input type="hidden" name="thumb_sort[]" value="0">
							</div>
							<iframe id="upload_frame" class="upload_frame" src="rest.php?s=FIL/Index/onefile&filetype=File" frameborder="0"></iframe>
						</td>
					</tr>
				</table>
			</div>
		</form>
	</div>
	<div class="page_footer pdtd10">
		<input type="button" name="submit" id="submit" value="提交数据"  class="form_ele_submit"/>
		<input type="reset" name="reset" id="reset" value="清空数据"  class="form_ele_reset"/>
	</div>
</body>
<script type="text/javascript">
	//弹出窗口全局变量
	var api = frameElement.api, W = api.opener;

	$(function(){
		//上传缩略图（4:3）
		var UPLOAD_PATH = '{$UPLOAD_PATH}';
		window.dealSelectFile = function(data){
			$('#thumb_url').val(data.filekey);
			$('.thumb>img').attr('src',UPLOAD_PATH+data.filekey);
		}
		
		//滑动门
		$('.tabbar li').click(function(){
			var tabname = $('.tabbar>ul').attr('tabname');
			$('.tabbar li').removeClass('tabhover');
			$(this).addClass('tabhover');
			
			$('div[fortab="'+tabname+'"]').hide();
			$('#'+$(this).attr('show')).show();
		});
		
		//表格隔行换色
		$('.module_form tr:odd').addClass('odd');
		$('.module_form tr:even').addClass('even');
		
		//表单操作
		//重置
		$('.form_ele_reset').on('click',function(){
			$('#memberAdd_form').get(0).reset();
		});

		//提交
		$('#submit').on('click',function(){
			//通过POST直接提交表单
			//$('#memberAdd_form').get(0).submit();
			//etcommon.maskShow();
			
			var tipsObj  = windowApi.lhgdialog.tips('正在提交数据...',5,etIcon.loading);
			var postData = $('#restaurantAdd_form').serialize();
			
			//通过Ajax提交表单
			postData += '&city='+$('#area2').val();
			
			$.post("{:U('Product/drinkAdd')}", postData ,function(data){
					windowApi.lhgdialog.tips('数据提交成功！',1,etIcon.success,function(){
						frameApi.close(); //关闭当前窗口
						if(data.status==1){
							var obj = windowApi.lhgdialog.list['Product_drink'];
							obj.reload(obj);
						}else{
							windowApi.lhgdialog.alert(data.info,function(){return;});
						}
					});
				}, "json");
		});
	});
	
	var linkage_json   = {$json|json_encode} ;
	$(function(){
		//初始值处理
		var did = '';
		if(did!=''){
			$('#areaBox').html(dealInitialarea(did,'',1));
		}else{
			$('#areaBox').html(showLinkagearea(39,2,0));
		}
		$('select[name="area"]').live('change',function(){
			var nowLevel  = parseInt($(this).attr('level'));
			var nextLevel = nowLevel+1;
			var enhtml    = '';
			
			//清除自此以后的select
			$('select[name="area"]').each(function(index, element) {
				if(parseInt($(this).attr('level'))>nowLevel){
					$(this).remove();
				}
			});
			$('#ssxadd').val($('select[name="area"]').find("option:selected").text());
			
			$('input[name="area'+nowLevel+'"]').val($(this).val());
			//显示下一个select
			$('#areaBox').append(showLinkagearea($(this).val(),nextLevel,0));
		});
		
		//处理初始值
		function dealInitialarea(lid,result,level){
			if(lid){
				$.each(linkage_json , function(i, n){
					if(lid==i){
						result = dealInitialarea(n[1],result,(parseInt(level)-1))+''+showLinkagearea(n[1],level,i);
						return false;
					}
				});
			}
			return result;
		}
		
		//响应select改变事件
		function showLinkagearea(pid,level,nid){
			var html = ''; //最终输出的HTML
			var have = false; //是否有子词典
			html += '<select name="area" id="area'+level+'" level="'+level+'" class="width_100">';
			html += '<option value="0">请选择</option>';
			$.each(linkage_json , function(i, n){
				if(pid==n[1]){
					if(nid==i){
						html += '<option value="'+i+'" selected>'+n[0]+'</option>';
					}else{
						html += '<option value="'+i+'">'+n[0]+'</option>';
					}
					have = true;
				}
			});
			html += '</select>';
			html += '<input type="hidden" name="area'+level+'"/>';
			
			//没有子词典则此次输出为空
			if(!have){
				html = '';
			}
			
			return html;
		}
	});
</script>
</html>
